<?php
require_once '../../../config/common_config.php';
require_once PATH_ROOT.'/inc/global.php';
require_once('.config.inc.php');
$db = createMysqlDbLink($mysql_config["of"]);
ini_set('date.timezone','Etc/GMT');
require_once('.config.inc.php');
$account='Zity-US';
$author=$db->getValue("select `author` from `auth` where `source` like 'amazon' and `account` like '".$account."'");
$auth=json_decode($author,true);

/************************************************************************
 * Instantiate Implementation of MarketplaceWebServiceOrders
 *
 * AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants
 * are defined in the .config.inc.php located in the same
 * directory as this sample
 ***********************************************************************/
// More endpoints are listed in the MWS Developer Guide
// North America:
//$serviceUrl = "https://mws.amazonservices.com/Orders/2013-09-01";
// Europe
//$serviceUrl = "https://mws-eu.amazonservices.com/Orders/2013-09-01";
// Japan
//$serviceUrl = "https://mws.amazonservices.jp/Orders/2013-09-01";
// China
//$serviceUrl = "https://mws.amazonservices.com.cn/Orders/2013-09-01";


 $config = array (
   'ServiceURL' => $serviceUrl,
   'ProxyHost' => null,
   'ProxyPort' => -1,
   'ProxyUsername' => null,
   'ProxyPassword' => null,
   'MaxErrorRetry' => 3,
 );

 $service = new MarketplaceWebServiceOrders_Client(
        $auth['AWS_ACCESS_KEY_ID'],
        $auth['AWS_SECRET_ACCESS_KEY'],
        APPLICATION_NAME,
        APPLICATION_VERSION,
        $config);

/************************************************************************
 * Uncomment to try out Mock Service that simulates MarketplaceWebServiceOrders
 * responses without calling MarketplaceWebServiceOrders service.
 *
 * Responses are loaded from local XML files. You can tweak XML files to
 * experiment with various outputs during development
 *
 * XML files available under MarketplaceWebServiceOrders/Mock tree
 *
 ***********************************************************************/
 // $service = new MarketplaceWebServiceOrders_Mock();

/************************************************************************
 * Setup request parameters and uncomment invoke to try out
 * sample for List Orders By Next Token Action
 ***********************************************************************/
 // @TODO: set request. Action can be passed as MarketplaceWebServiceOrders_Model_ListOrdersByNextToken
 $request = new MarketplaceWebServiceOrders_Model_ListOrdersByNextTokenRequest();
 $request->setSellerId($auth['MERCHANT_ID']);
 $request->setNextToken('WmqtXpEe1OCv06krKetbKrtwX7u5furPmv5KhOOR6lX9sRnTC7+k8iJ0wMvlylZkWQWPqGlbsnM84qdTrqNK4w8vijqRGVGUMGnWVhwnZjespe/FBedDKruZIF9n45mtnrZ4AbBdBTeicp5jJPQPcgCy5/GuGI4OLzyB960RsbIZEWUDFvtT53MCa7WeQ/rKwRKxLBvOKmDufQTOmk5l8dZ3/03LH+oNv5k/ISDhe7NeljXwPYcLzWv6blqJL3Z7h8DdYpeAs81nuRNsIPkVTlIGuiR+f8b4nPZ9+DnBy84wHw1AQ8Ha/P0IfGeAvb95x+mIjiAqdq7XKs1Ol1dxk5J7UX1K6D3SrVAlRqj6TtUD2s1QD6a1FV3fNFGc22MxZvsy0W2YjOJPYzSurxMGtxQ3QE8tRVA4ohI6er+RgHItqva3YSH2B6jVB4p8flFRrbBFEGYvapD19IS6jEttXa06ALGDfN7BxzNrFQXPPPdbq7rHZkNeM5GLiLVUOVHX3CrZByg5Uf6D6AY4zro8s4ve2rtIAhQlbeoQ2/g5KFgdITMxsDLfzO0NedbEoLsk4JHWT14XEXBUt40Jpkc7WRQFsW62bGV9');
 // object or array of parameters
 invokeListOrdersByNextToken($service, $request);

/**
  * Get List Orders By Next Token Action Sample
  * Gets competitive pricing and related information for a product identified by
  * the MarketplaceId and ASIN.
  *
  * @param MarketplaceWebServiceOrders_Interface $service instance of MarketplaceWebServiceOrders_Interface
  * @param mixed $request MarketplaceWebServiceOrders_Model_ListOrdersByNextToken or array of parameters
  */

  function invokeListOrdersByNextToken(MarketplaceWebServiceOrders_Interface $service, $request)
  {
      try {
        $response = $service->ListOrdersByNextToken($request);

        echo ("Service Response\n");
        echo ("=============================================================================\n");

        $dom = new DOMDocument();
        $dom->loadXML($response->toXML());
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = true;
        echo $dom->saveXML();
        echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");

     } catch (MarketplaceWebServiceOrders_Exception $ex) {
        echo("Caught Exception: " . $ex->getMessage() . "\n");
        echo("Response Status Code: " . $ex->getStatusCode() . "\n");
        echo("Error Code: " . $ex->getErrorCode() . "\n");
        echo("Error Type: " . $ex->getErrorType() . "\n");
        echo("Request ID: " . $ex->getRequestId() . "\n");
        echo("XML: " . $ex->getXML() . "\n");
        echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
     }
 }

